<?php

namespace app\admin\service\yun;

use app\admin\model\yun\BoxYunFreeGetLog;
use app\admin\service\BaseService;


/**
 * 云挂机服务类
 */
class BoxYunFreeGetLogService extends BaseService
{

    /**
     * @var BoxYunFreeGetLog
     */
    protected $model;

    public function __construct()
    {
        $this->model = new BoxYunFreeGetLog();
    }

    public function getList(): array
    {
        $params = request()->param();
        $page   = request()->param('page', 1);
        $limit  = request()->param('limit', 15);

        $time = $params['time_range'] ?? [];
        $list = $this->model;
        if(!empty($time)){
            $start = date('Ymd',strtotime($time[0]));
            $end = date('Ymd',strtotime($time[1]));;
            $where[] = ['day_time', 'between', [$start, $end]];
            $list = $this->model->where($where)->where('day_time', 'between', [$start, $end]);
        }

        $list    = $list->order('day_time', 'desc')->paginate($limit)->toArray();
        //返回结果
        
        return array (
            "msg"   => '操作成功',
            "code"  => 0,
            "data"  => $list['data'],
            "count" => $list['total'],
        );
    }

    /**
     * 添加或编辑
     * @return mixed
     * @since 2021/6/9
     * @author ZhangXuanNeng
     */
    public function edit()
    {
        // 参数
        $data = request()->param();
        $id = $data['id'] ?? 0;
        if(!$id){
            $data['created_time'] = date('Y-m-d H:i:s');
        }
        $data['updated_time'] = date('Y-m-d H:i:s');
        return parent::edit($data); // TODO: Change the autogenerated stub
    }

    public function delete()
    {
        return parent::delete(); // TODO: Change the autogenerated stub
    }
}